
#include "test1.h"

void tenacitas::log::test1::wcnl( const level & p_level,
                                  logger & p_log,
				  const char * p_func,
                                  const char * p_file,				  
                                  int64_t p_line ) {
    std::cout << "Can not log for level '"
              << p_level.str( )
              << "', because current level is '"
              << p_log.get_level( ).str( )
              << "', in "
              << p_file << ", "
              << p_func << ", "
              << p_line << std::endl;
}

void tenacitas::log::test1::f0( logger_factory & p_logger_factory ) {
    try {
        logger & l_log = p_logger_factory.create( );

        if ( l_log.can_log( level::debug ) ) {
            log_debug( l_log ) << "logging in 'f0'!!!";
        }
        else {
            wcnl( level::debug, l_log, __func__, __FILE__, __LINE__ );
        }
        
    }    
    catch ( std::string & l_ex ) {
        std::cout << "exception: '" << l_ex << "'" << std::endl;
    }
}

void tenacitas::log::test1::f1( logger_factory & p_logger_factory ) {
    try {
        logger & l_log = p_logger_factory.create( );
        
        if ( l_log.can_log( level::error ) ) {
            log_error( l_log ) << "hello " << 998;
        }
        else {
            wcnl( level::error, l_log, __func__, __FILE__, __LINE__ );
        }

        if ( l_log.can_log( level::trace ) ) {
            log_trace( l_log ) << "new line?";
        }
        else {
            wcnl( level::trace, l_log, __func__, __FILE__, __LINE__ );
        }

	
        if ( l_log.can_log( level::info ) ) {
            log_info( l_log ) << "not yet";
        }
        else {
            wcnl( level::info, l_log, __func__, __FILE__, __LINE__ );
        }
	
        if ( l_log.can_log( level::trace ) ) {
            log_trace( l_log ) << "counting: " << 1 << ", " << 2 << ", " << 3;
        }
        else {
            wcnl( level::trace, l_log, __func__, __FILE__, __LINE__ );
        }


        f0( p_logger_factory );
    }
    catch ( std::string & l_ex ) {
        std::cout << "exception: '" << l_ex << "'" << std::endl;
    }    
        
}


void tenacitas::log::test1::f2( logger_factory & p_logger_factory ) {
    try {
        logger & l_log = p_logger_factory.create( );
        
        if ( l_log.can_log( level::warn ) ) {
            log_warn( l_log ) << "how are you doing?";
        }
        else {
            wcnl( level::warn, l_log, __func__, __FILE__, __LINE__ );
        }
	
        if ( l_log.can_log( level::trace ) ) {
            log_trace( l_log ) << "just fine";
        }
        else {
            wcnl( level::trace, l_log, __func__, __FILE__, __LINE__ );
        }

        f0( p_logger_factory );

        log_critical( l_log ) << "ouch";
    }    
    catch ( std::string & l_ex ) {
        std::cout << "exception: '" << l_ex << "'" << std::endl;
    }
}

void tenacitas::log::test1::f3( logger_factory & p_logger_factory ) {
    try {
        logger & l_log = p_logger_factory.create( );
        
        if ( l_log.can_log( level::debug ) ) {
            log_debug( l_log ) << "logging in 'f3'";
        }
        else {
            wcnl( level::debug, l_log, __func__, __FILE__, __LINE__ );
        }        
    }    
    catch ( std::string & l_ex ) {
        std::cout << "exception: '" << l_ex << "'" << std::endl;
    }
}

void tenacitas::log::test1::f4( logger_factory & p_logger_factory ) {
    try {
        logger & l_log = p_logger_factory.create( );
        
        if ( l_log.can_log( level::debug ) ) {
            log_debug( l_log ) << "logging in 'f4'!!!";
        }
        else {
            wcnl( level::debug, l_log, __func__, __FILE__, __LINE__ );
        }                
    }    
    catch ( std::string & l_ex ) {
        std::cout << "exception: '" << l_ex << "'" << std::endl;
    }
}

void tenacitas::log::test1::f5( logger_factory & p_logger_factory ) {
    try {
        logger & l_log = p_logger_factory.create( );
        
        if ( l_log.can_log( level::warn ) ) {
            log_warn( l_log ) << "logging in 'f5'!!!";
        }
        else {
            wcnl( level::warn, l_log, __func__, __FILE__, __LINE__ );
        }        
    }    
    catch ( std::string & l_ex ) {
        std::cout << "exception: '" << l_ex << "'" << std::endl;
    }
}


void tenacitas::log::test1::f6( logger_factory & p_logger_factory ) {
    try {
        logger & l_log = p_logger_factory.create( );
        
        if ( l_log.can_log( level::debug ) ) {
            log_debug( l_log ) << "logging in 'f6'!!!";
        }
        else {
            wcnl( level::debug, l_log, __func__, __FILE__, __LINE__ );
        }        
    }    
    catch ( std::string & l_ex ) {
        std::cout << "exception: '" << l_ex << "'" << std::endl;
    }
}

void tenacitas::log::test1::f7( logger_factory & p_logger_factory ) {
    try {
        logger & l_log = p_logger_factory.create( );
        
        if ( l_log.can_log( level::warn ) ) {
            log_warn( l_log ) << "logging in 'f7'!!!";
        }
        else {
            wcnl( level::warn, l_log, __func__, __FILE__, __LINE__ );
        }
    }    
    catch ( std::string & l_ex ) {
        std::cout << "exception: '" << l_ex << "'" << std::endl;
    }
}

void tenacitas::log::test1::f8( logger_factory & p_logger_factory ) {
    try {
        logger & l_log = p_logger_factory.create( );

        p_logger_factory.set_level( level::trace );
        
        if ( l_log.can_log( level::debug ) ) {
            log_debug( l_log ) << "logging in 'f8'!!!";
        }
        else {
            wcnl( level::debug, l_log, __func__, __FILE__, __LINE__ );
        }

        
    }    
    catch ( std::string & l_ex ) {
        std::cout << "exception: '" << l_ex << "'" << std::endl;
    }
}


